package com.tastyshop.service;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import com.tastyshop.domain.Email;

@Component
public class MailService {
	
	@Autowired
	public JavaMailSender javaMailSender;

	public void SendEmail(Email mail) throws Exception{
		MimeMessage msg = javaMailSender.createMimeMessage();
		msg.setSubject(mail.getSubject());
		msg.setText(mail.getContent());
		msg.setRecipient(RecipientType.TO, new InternetAddress(mail.getReciver()));
		
		javaMailSender.send(msg);
	}
}